home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cvs / sprite / save / collect_sets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-29  |  8.4 KB  |  315 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Id: collect_sets.c,v 1.15.1.1 91/01/29 07:16:13 berliner Exp $";
  3. #endif !lint
  4.  
  5. /*
  6.  *    Copyright (c) 1989, Brian Berliner
  7.  *
  8.  *    You may distribute under the terms of the GNU General Public License
  9.  *    as specified in the README file that comes with the CVS 1.0 kit.
  10.  *
  11.  * Collect Sets
  12.  *
  13.  *    Collects the interesting file names from the administration and
  14.  *    the repository in a number of variables:
  15.  *                            solved by:
  16.  *        Clist    conflict-ridden            (user)
  17.  *        Glist    modified, needs merging        (update)
  18.  *        Mlist    modified, needs checking in    (commit)
  19.  *        Olist    needs checking out        (update)
  20.  *        Alist    to be added            (commit)
  21.  *        Rlist    to be removed            (commit)
  22.  *        Wlist    remove entry            (update)
  23.  *        Llist    locked list            (commit)
  24.  *        Blist    branch list            (commit)
  25.  *        Dlist    directory list            (update)
  26.  *        Slist    symbolic link list        (update)
  27.  *
  28.  *    Returns non-zero on error.
  29.  */
  30.  
  31. #include <sys/param.h>
  32. #include "cvs.h"
  33.  
  34. extern char update_dir[];
  35.  
  36. Collect_Sets(argc, argv)
  37.     int argc;
  38.     char *argv[];
  39. {
  40.     register int i;
  41.     char tmp[MAXPATHLEN], update_user[MAXPATHLEN];
  42.     int ret = 0;
  43.  
  44.     /*
  45.      * By default, a call here must wipe the slate clean
  46.      */
  47.     Clist[0] = Glist[0] = Mlist[0] = Olist[0] = Dlist[0] = '\0';
  48.     Alist[0] = Rlist[0] = Wlist[0] = Llist[0] = Blist[0] = '\0';
  49.     Slist[0] = '\0';
  50.     for (i = 0; i < argc; i++) {
  51.     (void) strcpy(User, argv[i]);
  52.     if (update_dir[0] != '\0')
  53.         (void) sprintf(update_user, "%s/%s", update_dir, User);
  54.     else
  55.         (void) strcpy(update_user, User);
  56.     if (force_tag_match && (Tag[0] != '\0' || Date[0] != '\0'))
  57.         Locate_RCS();
  58.     else
  59.         (void) sprintf(Rcs, "%s/%s%s", Repository, User, RCSEXT);
  60.     (void) sprintf(tmp, "%s/%s", Repository, User);
  61.     if (isdir(User)) {        /* just a directory -- add to Dlist */
  62.         (void) strcat(Dlist, " ");
  63.         (void) strcat(Dlist, User);
  64.         continue;
  65.     }
  66.     if (islink(tmp)) {
  67.         (void) strcat(Slist, " ");
  68.         (void) strcat(Slist, User);
  69.         continue;
  70.     } 
  71.     Version_TS(Rcs, Tag, User);
  72.     if (VN_User[0] == '\0') {
  73.         /*
  74.          * No entry available, TS_Rcs is invalid
  75.          */
  76.         if (VN_Rcs[0] == '\0') {
  77.         /*
  78.          * There is no RCS file either
  79.          */
  80.         if (TS_User[0] == '\0')    { /* there is no user file */
  81.             /* 
  82.              * 
  83.             if (!force_tag_match || !isfile(Rcs)) {
  84.             warn(0, "nothing known about %s", update_user);
  85.             ret++;
  86.             }
  87.         } else {        /* there is a user file */
  88.             if (!force_tag_match) {
  89.             warn(0, "use `cvs add' to create entry for %s",
  90.                  update_user);
  91.             ret++;
  92.             }
  93.         }
  94.         } else {
  95.         /*
  96.          * There is an RCS file
  97.          */
  98.         if (TS_User[0] == '\0') {
  99.             /*
  100.              * There is no user file; ad it to the Olist
  101.              */
  102.             (void) strcat(Olist, " ");
  103.             (void) strcat(Olist, User);
  104.         } else {
  105.             /*
  106.              * There is a user file; print a warning and add it
  107.              * to the conflict list, Clist, only if it is indeed
  108.              * different from what we plan to extract
  109.              */
  110.             No_Difference(0);
  111.             if (strcmp(TS_Rcs, TS_User) == 0) {
  112.             (void) strcat(Olist, " ");
  113.             (void) strcat(Olist, User);
  114.             } else {
  115.             warn(0, "move away %s; it is in the way",
  116.                  update_user);
  117.             (void) strcat(Clist, " ");
  118.             (void) strcat(Clist, User);
  119.             ret++;
  120.             }
  121.         }
  122.         }
  123.     } else if (VN_User[0] == '0' && VN_User[1] == '\0') {
  124.         /*
  125.          * An entry for a new-born file; TS_Rcs is dummy
  126.          */
  127.         if (TS_User[0] == '\0') {
  128.         /*
  129.          * There is no user file, but there should be one;
  130.          * add it to the remove entry list.
  131.          */
  132.         warn(0, "warning: new-born %s has disappeared", update_user);
  133.         (void) strcat(Wlist, " ");
  134.         (void) strcat(Wlist, User);
  135.         } else {
  136.         /*
  137.          * There is a user file
  138.          */
  139.         if (VN_Rcs[0] == '\0') {
  140.             /*
  141.              * There is no RCS file, so add it to the add entry list
  142.              */
  143.             (void) strcat(Alist, " ");
  144.             (void) strcat(Alist, User);
  145.         } else {
  146.             /*
  147.              * There is an RCS file, so someone else must have
  148.              * checked one in behind our back; added to the conflict
  149.              * list
  150.              */
  151.             warn(0, "conflict: %s created independently by second party",
  152.              update_user);
  153.             (void) strcat(Clist, " ");
  154.             (void) strcat(Clist, User);
  155.             ret++;
  156.         }
  157.         }
  158.     } else if (VN_User[0] == '-') {
  159.         /*
  160.          * An entry for a removed file, TS_Rcs is invalid
  161.          */
  162.         if (TS_User[0] == '\0') {
  163.         /*
  164.          * There is no user file (as it should be)
  165.          */
  166.         (void) sprintf(tmp, "-%s", VN_Rcs);
  167.         if (strcmp(tmp, "-") == 0) {
  168.             /*
  169.              * There is no RCS file; this is all-right, but it
  170.              * has been removed independently by a second party;
  171.              * added to the remove entry list.
  172.              */
  173.             (void) strcat(Wlist, " ");
  174.             (void) strcat(Wlist, User);
  175.         } else if (strcmp(tmp, VN_User) == 0) {
  176.             /*
  177.              * The RCS file is the same version as the user file,
  178.              * and that's OK; added to the to be removed list
  179.              */
  180.             (void) strcat(Rlist, " ");
  181.             (void) strcat(Rlist, User);
  182.         } else {
  183.             /*
  184.              * The RCS file is a newer version than the user file;
  185.              * and this is defintely not OK; make it a conflict.
  186.              */
  187.             warn(0, "conflict: removed %s was modified by second party",
  188.              update_user);
  189.             (void) strcat(Clist, " ");
  190.             (void) strcat(Clist, User);
  191.             ret++;
  192.         }
  193.         } else {
  194.         /*
  195.          * The user file shouldn't be there
  196.          */
  197.         warn(0, "%s should be removed and is still there", update_user);
  198.         ret++;
  199.         }
  200.     } else {
  201.         /*
  202.          * A normal entry, TS_Rcs is valid
  203.          */
  204.         if (VN_Rcs[0] == '\0') {
  205.         /*
  206.          * There is no RCS file
  207.          */
  208.         if (TS_User[0] == '\0') {
  209.             /*
  210.              * There is no user file, so just remove the entry
  211.              */
  212.             warn(0, "warning: %s is not (any longer) pertinent",
  213.              update_user);
  214.             (void) strcat(Wlist, " ");
  215.             (void) strcat(Wlist, User);
  216.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  217.             /*
  218.              * The user file is still unmodified, so just remove it
  219.              * from the entry list
  220.              */
  221.             if (!force_tag_match || !isfile(Rcs)) {
  222.             warn(0, "%s is no longer in the repository",
  223.                  update_user);
  224.             (void) strcat(Wlist, " ");
  225.             (void) strcat(Wlist, User);
  226.             }
  227.         } else {
  228.             /*
  229.              * The user file has been modified and since it is no
  230.              * longer in the repository, a conflict is raised
  231.              */
  232.             if (!force_tag_match) {
  233.             Locate_RCS();
  234.             (void) No_Difference(0);
  235.             if (strcmp(TS_User, TS_Rcs) == 0) {
  236.                 warn(0,
  237.         "warning: %s is not (any longer) pertinent",
  238.                  update_user);
  239.                 (void) strcat(Wlist, " ");
  240.                 (void) strcat(Wlist, User);
  241.             } else {
  242.                 warn(0,
  243.         "conflict: %s is modified but no longer in the repository",
  244.                  update_user);
  245.                 (void) strcat(Clist, " ");
  246.                 (void) strcat(Clist, User);
  247.                 ret++;
  248.             }
  249.             }
  250.         }
  251.         } else if (strcmp(VN_Rcs, VN_User) == 0) {
  252.         /*
  253.          * The RCS file is the same version as the user file
  254.          */
  255.         if (TS_User[0] == '\0') {
  256.             /*
  257.              * There is no user file, so note that it was lost
  258.              * and extract a new version
  259.              */
  260.             if (strcmp(command, "checkout") != 0 &&
  261.             strcmp(command, "co") != 0 &&
  262.             strcmp(command, "get") != 0)
  263.             warn(0, "warning: %s was lost", update_user);
  264.             (void) strcat(Olist, " ");
  265.             (void) strcat(Olist, User);
  266.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  267.             /*
  268.              * The user file is still unmodified, so nothing
  269.              * special at all to do -- no lists updated
  270.              */
  271.         } else {
  272.             /*
  273.              * The user file appears to have been modified, but
  274.              * we call No_Difference to verify that it really
  275.              * has been modified -- it updates the Mlist,
  276.              * if necessary.
  277.              */
  278.             (void) No_Difference(0);
  279.         }
  280.         } else {
  281.         /*
  282.          * The RCS file is a newer version than the user file
  283.          */
  284.         if (TS_User[0] == '\0') {
  285.             /*
  286.              * There is no user file, so just get it
  287.              */
  288.             if (strcmp(command, "checkout") != 0 &&
  289.             strcmp(command, "co") != 0 &&
  290.             strcmp(command, "get") != 0)
  291.             warn(0, "warning: %s was lost", update_user);
  292.             (void) strcat(Olist, " ");
  293.             (void) strcat(Olist, User);
  294.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  295.             /*
  296.              * The user file is still unmodified, so just get it
  297.              * as well
  298.              */
  299.             (void) strcat(Olist, " ");
  300.             (void) strcat(Olist, User);
  301.         } else {
  302.             /*
  303.              * The user file appears to have been modified; we call
  304.              * No_Difference to verify this for us, and it updates
  305.              * Glist if it has really been modified, and Olist if
  306.              * it hasn't
  307.              */
  308.             (void) No_Difference(1);
  309.         }
  310.         }
  311.     }
  312.     }
  313.     return (ret);
  314. }
  315.